﻿using System;
using System.Collections.Generic;
using System.Text;
using VCDepend.Engine;
using VCDepend.Engine.Graphviz;
using System.IO;

namespace VCDepend.Console
{
  public class DotBuilder : IDependencyAction
  {
    private DotGraph m_graph;

    public DotBuilder(string name)
    {
      m_graph = new DotGraph(name);

      AddFormatting();
    }

    public void OnDependencyNode(string name, string[] dependencies)
    {
      m_graph.AddNode(name);

      foreach (string dependency in dependencies)
      {
        m_graph.AddEdge(name, dependency);
      }
    }

    public void WriteTo(TextWriter writer)
    {
      m_graph.Serialize(writer);
    }

    private void AddFormatting()
    {
      m_graph.SetAttribute("ratio", "1");

      DotNode node = m_graph.AddNode("node");
      node.SetAttribute("shape", "box");
      node.SetAttribute("fontname", "Verdana");
    }
  }
}
